package com.example.bishe.demos.web;

import com.example.bishe.entity.Worker;
import com.example.bishe.mapper.WorkerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin              //允许跨域
@RestController
public class UserController {

    @Autowired
    private WorkerMapper workerMapper;

    @GetMapping("/user/find")
    public List query() {
        List<Worker> list = workerMapper.selectList(null);//查询用户页面测试
        System.out.println(list);
        return list;
    }

    @PostMapping
    public String save(Worker worker) {
        int i = workerMapper.insert(worker);
        if (i > 0) {
            return "插入成功";
        } else {
            return "插入失败";
        }
    }
}
//    @GetMapping("/user/{id}")
//    public String getUserById(@PathVariable int id) {
//        System.out.println(id);
//        return "根据ID获取用户信息";
//    }
//    @PostMapping("/user")
//    public String save(User user) {
//        return "添加用户";
//    }
//    @PutMapping("/user")
//    public String update(User user) {
//        return "更新用户";
//    }
//    @DeleteMapping("/user/{id}")
//    public String deleteById(@PathVariable int id) {
//        System.out.println(id);
//        return "根据ID删除用户";
//    }
//}
